package com.cykj.cotroller;

import com.cykj.dto.ResponseDto;
import com.cykj.pojo.User;
import com.cykj.service.LoginService;
import com.cykj.util.RedisUtil;
import com.cykj.vo.loginVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/user")
public class LoginController {
    @Autowired
    private LoginService loginService;
    @Resource
    private RedisUtil redisUtil;
   @RequestMapping("/login")
   @ResponseBody
   public ResponseDto login(@RequestBody loginVo vo){
//       System.out.println("dffdfdfdfd"+vo.getCode());
//       System.out.println("dsdsds"+session.getAttribute("code"));
//       if (vo.getCode().equals(session.getAttribute("code"))) {
//           System.out.println("sdsdsdsdsdsdsd"+vo.getCode());
//           return loginService.login(vo.getUser_input(), vo.getUser_pwd());
//       }
//       return new ResponseDto(2, "验证码失败", null);
       String code = (String) redisUtil.get("code");
       System.out.println(code);
       System.out.println(vo.getUser_input());
       System.out.println(vo.getUser_pwd());
       if(vo.getCode().equals(code)){
           return loginService.login(vo.getUser_input(),vo.getUser_pwd());
       }
       return new ResponseDto(2,"验证码失效",null);
   }
    @RequestMapping("/loginUser")
    @ResponseBody
    public User LoginUser(@RequestBody loginVo vo) {
        User user = loginService.LoginUser(vo.getUserId());
        return user;
    }

}
